﻿using System.Globalization;
using System.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace System.Modules.SharePoint.Extensions
{
    /// <summary>
    /// SP Feature Definition Extensions
    /// </summary>
    public static class SPFeatureDefinitionExtensions
    {
        /// <summary>
        ///  Update Files In Modules
        /// </summary>
        /// <param name="definition"></param>
        /// <param name="web"></param>
        public static void UpdateFilesInModules(this SPFeatureDefinition definition, SPWeb web)
        {
            if (definition != null && web != null)
            {
                SPElementDefinitionCollection elementDefinitions = definition.GetElementDefinitions(CultureInfo.CurrentCulture);

                foreach (SPElementDefinition elementDefinition in elementDefinitions.Cast<SPElementDefinition>().Where(elementDefinition => elementDefinition.ElementType.Equals("Module", StringComparison.InvariantCultureIgnoreCase)))
                {
                    elementDefinition.UpdateFilesInModule(web);
                }
            }
        }
    }
}